<script setup>
import { ref, defineEmits, nextTick } from 'vue'

const emit = defineEmits(["search"])

const searchClick = () => {
  emit('search', input_key.value)
}

const input_key = ref('')

const inputRef = ref()
nextTick(() => {
  inputRef.value.focus()
})
</script>

<template>
  <div class="input_box">
    <img class="icon" src="@/assets/images/icons/search_icon.png" alt="">
<!--    :placeholder="keyword"-->
    <input
      v-model="input_key"
      @keyup.enter="searchClick"
      class="input"
      ref="inputRef"
      placeholder="搜索景区、酒店和活动等"
    />
    <div class="search_button" @click="searchClick">搜索</div>
  </div>
</template>

<style scoped lang="scss">
.input_box {
  flex: 1;
  display: flex;
  align-items: center;
  height: 3.5rem;
  border-radius: 3rem;
  border: 1px solid var(--van-primary-color);
  margin: 1.5rem;
  background: #FFFFFC;
  padding-left: .5rem;
  .icon{
    padding-left: .5rem;
  }
  .input {
    width: calc(100% - 6rem);
    border: none;
    outline: none;
    box-sizing: border-box;
    background-color: transparent;
    color: #666666;
  }
  .input::placeholder{
    color: #BBBBBB;
  }

  .search_button {
    height: 2.9rem;
    background-color: var(--van-primary-color);
    width: 7rem;
    border-radius: 3rem;
    line-height: 3rem;
    margin-right: .3rem;
    text-align: center;
    color: #ffffff;
    padding-left: .4rem;
  }

  .search_button:active {
    background-color: rgb(41 142 142);
  }
}
</style>